package cn.wolfcode.wolf2w.listener;

import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisDataInitListener implements ApplicationListener<ContextRefreshedEvent> {

        @Autowired
        private IStrategyService strategyDetailService;

        @Autowired
        private IStrategyStatisVORedisService strategyStatisRedisService;


        @Override
        public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
                System.out.println("---------------begin---------------------");
                {
                        List<Strategy> strategies = strategyDetailService.list();
                        for (Strategy strategy : strategies) {
                                StrategyStatisVO vo = new StrategyStatisVO();
                                if (strategyStatisRedisService.hasStatisKey(strategy.getId())) {
                                        continue;
                                }
                                System.out.println(123);
                                BeanUtils.copyProperties(strategy, vo);
                                vo.setStrategyId(strategy.getId());
                                strategyStatisRedisService.setStatisVO(strategy.getId(), vo);
                        }
                }
                System.out.println("---------------end---------------------");
        }
}
